﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace GotLyrics.PropertyPages
{
    public partial class LyricsPropertiesControl : PropertyPageControl
    {
        UltraGrabber _grabber = new UltraGrabber();

        public LyricsPropertiesControl()
        {
            InitializeComponent();

            FillSourceComboBox();
        }

        private void FillSourceComboBox()
        {
            sourceComboBox.Items.Clear();

            sourceComboBox.Items.Add("Local file");

            if (_grabber.LyricGrabbers != null)
            {
                foreach (ILyricGrabber grabber in _grabber.LyricGrabbers)
                {
                    if (grabber.Enabled)
                    {
                        GrabberWrapper w = new GrabberWrapper(grabber);
                        sourceComboBox.Items.Add(w);
                    }
                }
            }

            sourceComboBox.SelectedIndex = 0;
        }

        public override void ReflectSelection()
        {
            lyricsTextBox.Text = null;
            FillSourceComboBox();
        }

        private class GrabberWrapper
        {
            private ILyricGrabber _grabber;
            /// <summary>
            /// Gets the grabber.
            /// </summary>
            /// <value>The grabber.</value>
            public ILyricGrabber Grabber
            {
                get { return _grabber; }
            }

            /// <summary>
            /// Initializes a new instance of the <see cref="GrabberWrapper"/> class.
            /// </summary>
            /// <param name="grabber">The grabber.</param>
            public GrabberWrapper(ILyricGrabber grabber)
            {
                _grabber = grabber;
            }

            /// <summary>
            /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
            /// </summary>
            /// <returns>
            /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
            /// </returns>
            public override string ToString()
            {
                return _grabber.Name;
            }
        }

        private void sourceComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
           /* if (Selection != null && Selection.Count > 0)
            {
                if (sourceComboBox.SelectedItem.GetType() == typeof(GrabberWrapper))
                {
                    GrabberWrapper w = (GrabberWrapper)sourceComboBox.SelectedItem;

                    Cursor.Current = Cursors.WaitCursor;
                    lyricsTextBox.Text = w.Grabber.Execute(Selection[0]);
                    Cursor.Current = Cursors.Default;
                }
                else
                {
                    lyricsTextBox.Text = Selection[0].Tags.UnsyncedLyrics;
                }
            }*/
        }
    }
}
